package what.basic.menutoolbar;
import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;

import java.awt.*;
import java.awt.event.*;
public class Jradiobuttonmenuitem {
	JFrame f=null;
	JPopupMenu pop;
		JRadioButtonMenuItem mnuf1=new JRadioButtonMenuItem("open");
		public Jradiobuttonmenuitem(){
		f=new JFrame("menu window");
		JRootPane rp=new JRootPane();
		f.setContentPane(rp);
		JMenuBar mbar=new JMenuBar();
		rp.setJMenuBar(mbar);
		JMenu mnu1=new JMenu("file");
		JMenu mnu2=new JMenu("edit");
		mbar.add(mnu1);
		mbar.add(mnu2);
		mnuf1.setAccelerator(KeyStroke.getKeyStroke('O',java.awt.Event.CTRL_MASK,true));
		JCheckBoxMenuItem mnuf2=new JCheckBoxMenuItem("save");
		mnuf2.setAccelerator(KeyStroke.getKeyStroke('S',java.awt.Event.CTRL_MASK,true));
		JCheckBoxMenuItem mnuf3=new JCheckBoxMenuItem("exit");
		mnuf3.setAccelerator(KeyStroke.getKeyStroke('X',java.awt.Event.CTRL_MASK,true));
		mnu1.add(mnuf1);
		mnu1.setMnemonic('F');
		mnu1.add(mnuf2);
		mnu1.add(mnuf3);
		final JMenuItem mnue1=new JMenuItem("find",'f');
		JMenuItem mnue2=new JMenuItem("cut",'u');
		pop=new JPopupMenu();
		pop.add(mnue1);
		pop.add(mnue2);
		//pop.add(mnuf3);
		mnu2.add(mnue1);
		mnu2.add(mnue2);
		rp.addMouseListener(new MouseAdapter(){
			public void mouseReleased(MouseEvent e){
				if(e.isPopupTrigger())
					pop.show(e.getComponent(), e.getX(), e.getY());
			}
		});
		f.setSize(300,400);
		f.setVisible(true);
		//f.pack();
		mnuf3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				int i=JOptionPane.showConfirmDialog(null,"exit really?", "exit confirm",JOptionPane.YES_NO_CANCEL_OPTION);
				if(i==0)
					f.dispose();
			}
		});
		mnu2.addMenuListener(new MenuListener(){

			public void menuCanceled(MenuEvent e) {
			}
			public void menuDeselected(MenuEvent e) {
			}
			public void menuSelected(MenuEvent e) {
				mnue1.setEnabled(false);
			}
			
		});
	}
	public static void main(String[] args) {
		new Jradiobuttonmenuitem();

	}

}
